<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>商品列表</title>
<meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/alertMsg.js"></script>
<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/share_product.js?2014-01-05"></script>
<link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/css/product_list.css?v=2013-12-01">
	<style>
		.load-more {
			margin-left: auto;
			margin-right: auto;
			font-size: 15px;
			color: #3985FF !important;
			height: 23px;
			line-height: 23px;
			/*border: 1px solid #3e3e3e;*/
			display: block;
			width: 100%;
			text-align: center;
			background: #fff;
			padding:10px 0;
			/*background-color: #5d5554;*/
			/*background-image: -ms-linear-gradient(top, #5c5453 0%, #4b4443 100%);*/
			/*background-image: linear-gradient(top, #5c5453 0%, #4b4443 100%);*/
			/*background-image: -webkit-gradient(linear,0 0%,0% 100%,from(#5c5453),to(#4b4443));*/
		}
		.load-more:before{
			content: ' ';width: 8px;height: 8px;border-top: 1px solid #7d7d7d;
			border-left: 1px solid #7d7d7d;position:relative;display:inline-block;
			border-color:#3985FF;-webkit-transform: rotate(225deg);margin-right: 10px;margin-bottom: 3px;
		}
		.discount{
			text-align:center;
			background:#333;
			color:white;
			padding:0 5px;
			border-radius: 10px;
			width:auto;
			float:right;
			margin-right:10px
		}
	</style>
</head>
<body>
<notempty name="headerTpl">
	<include file="$headerTpl" />
</notempty>
<div class="lay_page page_cat_1">
	<div class="lay_page_wrap">
		<notempty name="headerpic">
		<div class="">
			<img class="ui_fluid" src="{$headerpic}" alt="" height="">
		</div>
		</notempty>
		<php>$num=0;$tag=0;</php>
        <volist name="item" id="item" key="k">
			<php>if($tag==0){</php>
            <div class="fn_titles">
                <h1>{$item.title}</h1>
                <h2 class="qb_fs_s">{$banner.description}</h2>
            </div>
            <div class="fn_goods qb_clearfix" id="pInfo">
                <ul id="show_container{$k}" >
                    <volist name="item.productList" id="product">
                    <li><a onclick="onDetail(this,{$product.id})">
                        <img
                            src="{$product.picUrl}"
                            width="140" height="140" class="default">
                            <div class="goods_name qb_fs_s mod_color_weak">{$product.name}</div>
                            <if condition="($product.fixedPrice neq NULL)">
                                <notempty name="product.discountedPrice">
                                    <div class="price qb_fs_s">市场价:<del>￥{$product.fixedPrice}</del></div>
                                    <div class="price qb_fs_s">折扣价:<span class="mod_color_strong">￥{$product.discountedPrice}</span></div>
									<php>if(floor($product['discountedPrice'] / $product['fixedPrice'] * 10)==($product['discountedPrice']/$product['fixedPrice']*10)){</php>
									<div ><span class="discount"><php> echo $product['discountedPrice'] / $product['fixedPrice'] * 10</php>折</span></div>
									<php>}else{</php>
									<div><span class="discount"><php> echo number_format($product['discountedPrice'] / $product['fixedPrice'] * 10,1)</php>折</span></div>
									<php>}</php>
                                 </notempty>
                                <empty name="product.discountedPrice">
                                    <div class="price qb_fs_s">市场价:￥{$product.fixedPrice}</div>
                                    <div class="price qb_fs_s">&nbsp;</div>
									<div class="price qb_fs_s">&nbsp;</div>
                                </empty>
                            <elseif condition="($product.points neq NULL)" />
                                <div class="points qb_fs_s">{$product.points}积分</div>
                                <div class="price qb_fs_s">&nbsp;</div>
								<div class="price qb_fs_s">&nbsp;</div>
                            <else />
								<div class="price qb_fs_s mod_color_strong">&nbsp;</div>
								<div class="price qb_fs_s mod_color_strong">&nbsp;</div>
								<div class="price qb_fs_s mod_color_strong">&nbsp;</div>

                            </if>
                            </a>

                        </li>
                    </volist>
                </ul>
			</div>
				<php> if( count($item['productList'])<$item['total']){</php>
					<div class="jx_map" style="width:100%;padding:10px 0">
						<a class="load-more" href="javascript:void(0);" onclick="loadmore(this,{$item.total},{$item.tagId});" data-start = "<php>echo count($item['productList']);</php>" data-key="{$k}">点击加载更多</a>
					</div>
				<php>}</php>
			<php>if(($num+=count($item['productList']))>6){</php>
			<php>$tag=1;</php>
			<php>}</php>
			<php>}</php>
        </volist>
		<notempty name="footerTpl">
			<include file="$footerTpl" />
		</notempty>
	</div>
</div>
<div class="qb_quick_tip qb_none" id="bubble"></div>
<script type="text/javascript" src="wx_assets/js/jquery-1.8.2.min.js"></script>

<script>
var hrefParamsArray = GetSessionIdFromHref(window.location.search);
hrefParamsArray["userName"]='{$userName}';
function GetSessionIdFromHref(search){
　　	var args = search.substring(1); 
　　	var retval = new Array(); 
	args = args.split("&"); 
		for(var i = 0; i < args.length; i ++){ 
			str = args[i]; 
			var arg = str.split("="); 
			if(arg.length <= 1) continue; 
			
			if(arg[0] == 'params') {
				var params = decodeURIComponent(arg[1]);
				var obj = eval('(' + params + ')');
				if (obj.rootid != undefined) {
					retval["rootid"] = obj.rootid;
				}
				if (obj.start != undefined) {
					retval["start"] = obj.start;
				}
				retval["id"] = obj.id;
			} else if(arg[0] == 'customerId') {
				retval["customerId"] = arg[1]; 
			}else if(arg[0] == 'userName'){
				retval["userName"] = arg[1]; 
			} else if(arg[0] == 'method') {
				retval["method"] = arg[1];
			} else if (arg[0] == 'module') {
				retval["module"] = arg[1];
			}
		} 
		
		if (retval["start"] == undefined) {
			retval["start"] = 0;
		}
		return retval; 
}

function onDetail(ctrl,id) {
	var rootid = '';
	if (hrefParamsArray["rootid"] !== undefined) {
		rootid = ',"rootid":' + hrefParamsArray["rootid"];
	}
	ctrl.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
	+ hrefParamsArray['customerId'] + '&module=product&method=getProduct&params={"tplid":1,"id":"' + id + rootid + '"}';
}
$(window).scroll(function(){
	if($(this).scrollTop()+window.innerHeight>=$(document).height()-100){
		var urlString = 'call.json?userName=' + hrefParamsArray['userName'] + '&customerId='
				+ hrefParamsArray['customerId'] ;
		$.ajax({
			url: urlString,
			dataType: "json",
			type: "post",
			data: {
				'module': 'mall',
				'method': 'getMall',
				'params': '{"id":' + hrefParamsArray["id"] + '}'
			},
			success: function (data) {
				var list = data.item;
				var tag = 0;
				var num = 0;
				var str ='';
				var index = $(".fn_titles").length;
				$.each(list,function(i){
					if(i>=index) {
						if (tag == 0) {
							str += '<div class="fn_titles">';
							str += '<h1>' + this.title + '</h1></div>';
							str += '<div class="fn_goods qb_clearfix" id="pInfo">';
							str += '<ul id="show_container' + i + '" >';
							$.each(this.productList, function () {
								str+='<li><a onclick="onDetail(this,'+this.id+')">';
								str+='<img src="'+this.picUrl+'" width="140" height="140" class="default">';
								str+='<div class="goods_name qb_fs_s mod_color_weak">'+this.name+'</div>';
								if(this.fixedPrice){
									if(this.discountedPrice){
										str+='<div class="price qb_fs_s">市场价:<del>￥'+this.fixedPrice+'</del></div>';
										str+='<div class="price qb_fs_s">折扣价:<span class="mod_color_strong">￥'+this.discountedPrice+'</span></div>';
										if(parseInt(this.discountedPrice/this.fixedPrice*10)==(this.discountedPrice/this.fixedPrice*10)){
											str+='<div><span class="discount">'+(this.discountedPrice/this.fixedPrice*10)+'</span>折</div>';
										}else{
											str+='<div><span class="discount">'+(this.discountedPrice/this.fixedPrice*10).toFixed(1)+'</span>折</div>';
										}
									}else{
										str+='<div class="price qb_fs_s">市场价:￥'+this.fixedPrice+'</div>';
										str+='<div class="price qb_fs_s">&nbsp;</div>';
										str+='<div class="price qb_fs_s">&nbsp;</div>';
									}
								}else if(this.points){
									str+='<div class="points qb_fs_s">'+this.points+'积分</div>';
									str+='<div class="price qb_fs_s">&nbsp;</div>';
									str+='<div class="price qb_fs_s">&nbsp;</div>';
								}else{
									str+='<div class="price qb_fs_s mod_color_strong">&nbsp;</div>';
									str+='<div class="price qb_fs_s mod_color_strong">&nbsp;</div>';
									str+='<div class="price qb_fs_s mod_color_strong">&nbsp;</div>';
								}
								str+='</a></li>';

							});
							str+='</ul>';
							if(this.productList.length<this.total){
								str+='<div class="jx_map" style="width:100%;padding:10px 0">';
								str+='<a class="load-more" href="javascript:void(0);" onclick="loadmore(this,'+this.total+','+this.tagId+');" ' +
								'data-start = "'+this.productList.length+'" data-key="'+i+'">点击加载更多</a></div>';
							}
							str+='</div>';
						}
						if((num+=this.productList.length)>6){
							tag=1;
						}
					}
				});
				$(".lay_page_wrap").append(str);
			}
		});
	}
});
</script>

<!--<script type="text/javascript" src="wx_assets/js/zepto_product.js?v=201401121"></script>-->
<script type="text/javascript">


	function loadmore(obj,total,productId) {
		var LIMIT = 4;
		var me = $(obj);
		var start =parseInt(me.data('start'));

		var index = me.data('key');
		var rootid = '';
		if (hrefParamsArray["rootid"] !== undefined) {
			rootid = ',"rootid":' + hrefParamsArray["rootid"];
		}
		var baseUrl = ' ';
		var urlString = baseUrl + 'call.json?customerId=' + hrefParamsArray["customerId"] + '&userName=' + hrefParamsArray["userName"];
		//var id = {$banner.id};
		var container = $("#show_container");
		var p =  '{"sid":-1,"tagId":'+productId+',"counts":' + (total - start) +',"cids":"","type":"buy","tplid":"4"'+ ',"start":' + start + ',"limit":' + (total - start) +'}';
		$.ajax({
			url: urlString,
			dataType: "json",
			type: "post",
			data: {
				'module': 'product',
				'method': 'getProductByTagId',
				'params': p
			},
			success: function (data) {
				if (data.code != undefined) {
					alert(data.msg);
					return;
				}
				var productList = data.list[0].productList;
				if (productList.length < LIMIT) {
					me.parent().remove();
				}
				for(var i in productList){
					if(i<LIMIT){
						var picUrl = productList[i].picUrl;
						var name = productList[i].name;
						var id = productList[i].id;
						var discountedPrice = productList[i].discountedPrice;
						var fixedPrice = productList[i].fixedPrice;
						var points = productList[i].points;
						var str = '<li><a onclick="onDetail(this,'+id+')">\
						<img src="'+picUrl+'" width="140" height="140" class="default">\
						<div class="goods_name qb_fs_s mod_color_weak">'+name+'</div>';
						if(fixedPrice){
							if(discountedPrice) {
								str += '<div class="price qb_fs_s">市场价:<del>￥' + fixedPrice + '</del></div>\
								<div class="price qb_fs_s">折扣价:<span class="mod_color_strong">￥' + discountedPrice + '</span></div>';
								if(parseInt(discountedPrice/fixedPrice*10)==(discountedPrice/fixedPrice*10)){
								str+='<div><span class="discount">'+(discountedPrice/fixedPrice*10)+'折</span></div>';
							}else{
								str+='<div><span class="discount">'+(discountedPrice/fixedPrice*10).toFixed(1)+'折</span></div>';
							}
							}else{
								str += '<div class="price qb_fs_s">市场价:￥' + fixedPrice + '</div>\
								<div class="price qb_fs_s">&nbsp;</div><div class="price qb_fs_s">&nbsp;</div>';
							}
						}else if(points){
							str+='<div class="points qb_fs_s">'+points+'积分</div>\
							<div class="price qb_fs_s">&nbsp;</div><div class="price qb_fs_s">&nbsp;</div>';
						}else{
							str+='<div class="price qb_fs_s mod_color_strong">&nbsp;</div>';
							str+='<div class="price qb_fs_s mod_color_strong">&nbsp;</div>';
							str+='<div class="price qb_fs_s mod_color_strong">&nbsp;</div>';
						}
						str+='</a></li>';
						$("#show_container"+index,top.window.document || document).append(str);
					}
				}
				start = start+LIMIT;
				me.data('start',start)
			}
		});
	};
</script>
                
<script type="text/javascript">
function resetAndAppendHerf(search){
　　	var args = search.substring(1); 
　　	var retval = new Array(); 
	args = args.split("&"); 
	for(var i = 0; i < args.length; i ++){ 
		str = args[i]; 
		var arg = str.split("="); 
		if(arg.length <= 1) continue; 
		if(arg[0] == 'userName'){
			args[i] = "userName=";
		}
	} 
	return args.join("&");
}

$(function(){
	var imageUrl = '{$banner.picUrl}';
	var title = '{$banner.name}';
	var des = '点击这里查看商品';
	var search = '?' + resetAndAppendHerf(window.location.search);
	var shareUrlString = window.location.protocol + "//"
			+ window.location.host + window.location.pathname + search;	      
	
	window.shareData = {
		"imgUrl": imageUrl,
		"timeLineLink":  shareUrlString ,
		"sendFriendLink":  shareUrlString ,
		"weiboLink":  shareUrlString ,
		"tTitle": title,
		"tContent": des,
		"fTitle": title,
		"fContent": des,
		"wContent": des
	};
	document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
		// 发送给好友
		WeixinJSBridge.on('menu:share:appmessage', function (argv) {
			WeixinJSBridge.invoke('sendAppMessage', {
				"img_url":  window.shareData.imgUrl,
				"img_width": "640",
				"img_height": "640",
				"link": window.shareData.sendFriendLink,
				"desc": window.shareData.fContent,
				"title": window.shareData.fTitle
			}, function (res) {
				_report('send_msg', res.err_msg);
			})
		});
	
		// 分享到朋友圈
		WeixinJSBridge.on('menu:share:timeline', function (argv) {
			WeixinJSBridge.invoke('shareTimeline', {
				"img_url": window.shareData.imgUrl,
				"img_width": "640",
				"img_height": "640",
				"link": window.shareData.timeLineLink,
				"desc": window.shareData.tContent,
				"title": window.shareData.tTitle
			}, function (res) {
				_report('timeline', res.err_msg);
			});
		});
	
		// 分享到微博
		WeixinJSBridge.on('menu:share:weibo', function (argv) {
			WeixinJSBridge.invoke('shareWeibo', {
				"content": window.shareData.wContent,
				"url": window.shareData.weiboLink
			}, function (res) {
				_report('weibo', res.err_msg);
			});
		});
	});
});
</script>

</body>
</html>